package com.usian.controller;

import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.service.ContentService;
import com.usian.utils.AdNode;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 内容分类管理查询
     * @param id
     * @return
     */
    @RequestMapping("selectContentCategoryByParentId")
    public List<TbContentCategory> selectContentCategoryByParentId(@RequestParam Long id){
        return contentService.selectContentCategoryByParentId(id);
    }

    /**
     * 内容分类管理添加
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("insertContentCategory")
    public Integer insertContentCategory(@RequestParam Long parentId,@RequestParam String name){
        return contentService.insertContentCategory(parentId,name);
    }

    /**
     * 内容分类管理删除
     * @param categoryId
     * @return
     */
    @RequestMapping("deleteContentCategoryById")
    Integer deleteContentCategoryById(@RequestParam Long categoryId){
        return contentService.deleteContentCategoryById(categoryId);
    }

    /**
     * 内容分类管理修改
     * @param id
     * @param name
     * @return
     */
    @RequestMapping("updateContentCategory")
    public Integer updateContentCategory(@RequestParam Long id, @RequestParam String name){
        return contentService.updateContentCategory(id,name);
    }

    /**
     * 内容管理	查询
     * @param categoryId
     * @return
     */
    @RequestMapping("selectTbContentAllByCategoryId")
    public PageResult selectTbContentAllByCategoryId(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5")Integer rows, @RequestParam Long categoryId){
        return contentService.selectTbContentAllByCategoryId(page,rows,categoryId);
    }

    /**
     * 内容管理  添加
     * @param tbContent
     * @return
     */
    @RequestMapping("insertTbContent")
    public Integer insertTbContent(@RequestBody TbContent tbContent){
        return contentService.insertTbContent(tbContent);
    }


    /**
     * 内容管理 删除
     * @param ids
     * @return
     */
    @RequestMapping("deleteContentByIds")
    public Integer deleteContentByIds(@RequestParam Long ids){
        return contentService.deleteContentByIds(ids);
    }

    /**
     * 首页大广告位
     *
     * @return
     */
    @RequestMapping("selectFrontendContentByAD")
    public List<AdNode> selectFrontendContentByAD(){
        return contentService.selectFrontendContentByAD();
    }

}
